package com.zyw.zhuangdian.dao.impl;

import com.zyw.zhuangdian.dao.BaseDao;
import com.zyw.zhuangdian.dao.FileDao;
import com.zyw.zhuangdian.exceptions.MyDaoException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository
@Transactional
public class FileDaoImpl extends BaseDao implements FileDao {
    @Override
    public void addFile(Map in) {
        int i = sqlTemplate.insert("FileDaoImpl.addFile",in);
        if (i<1){
            throw new MyDaoException("插入文件记录失败");
        }
    }

    @Override
    public void updateFile(Map in) {
        int i = sqlTemplate.update("FileDaoImpl.updateFile",in);
        if (i<1){
            throw new MyDaoException("更新文件记录失败");
        }
    }

    @Override
    public List<Map> listFiles(Map in) {
        List<Map> list = sqlTemplate.selectList("FileDaoImpl.listFiles",in);
        return list;
    }

    @Override
    public int listFilesCount(Map in) {
        List<Map> list = sqlTemplate.selectList("FileDaoImpl.listFilesCount",in);
        if (list.size() < 1){
            return 0;
        }
        return Integer.parseInt(list.get(0).get("count").toString());
    }
}
